package com.xcjh.opencv.rule;

import cn.hutool.core.io.FileUtil;
import com.xcjh.opencv.FindSimilarImage;
import com.xcjh.opencv.ImageUtil;
import com.xcjh.opencv.emuns.MatchImage;
import org.opencv.core.Core;

import java.awt.*;
import java.util.List;

/**
 * @author yangyi
 */
public interface BaseRule {
    /**
     * 获取规则名称
     * @return
     */
    String getRuleName();

    /**
     * 运行规则
     */
    void run(Robot robot) throws Exception;

    /**
     * 执行规则文件
     * @param robot
     * @param ruleFile
     */
    default void exeRule(Robot robot,String ruleFile){
        //idea 设置 文件类型 配置改为utf-8
        List<String> rules = FileUtil.readUtf8Lines("script/"+ruleFile);
        for (String command : rules) {
            if(FindSimilarImage.go){
                ImageUtil.exeRule(command,robot);
            }else {
                break;
            }
        }
    }

    default boolean findAndClickPic(MatchImage image,Robot robot) throws Exception {
        Core.MinMaxLocResult image1 = ImageUtil.findImage(image, robot);
        if(image1!=null){
            ImageUtil.movePicAndClick(image1,robot,image);
            return true;
        }else {
            return false;
        }
    }
}
